home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Modules / BackSpaceModules / Source / QizColorView / QixView.m < prev    next >
Text File  |  1991-11-07  |  4KB  |  199 lines

  1.  
  2. #import    <stdlib.h>
  3. #import    <math.h>
  4. #import    <appkit/Application.h>
  5. #import    <appkit/Slider.h>
  6. #import    <appkit/Button.h>
  7. #import    <appkit/NXImage.h>
  8. #import <appkit/color.h>
  9. #import    <dpsclient/wraps.h>
  10. #import    "QixView.h"
  11.  
  12. /**********************************************************************/
  13.  
  14. #define    LEFT        ( 100 )
  15. #define    RIGHT        ( 101 )
  16. #define    UP            ( 102 )
  17. #define    DOWN        ( 103 )
  18.  
  19. #define    INITLEN        ( 55 )                //    Initial qix tail length.
  20.  
  21. #define    A_BASE_INC    ( 5 )                //    Default distance to move the
  22.                                         //    "A" point of a qix structure.
  23. #define    B_BASE_INC    ( 8 )                //    Default distance to move the
  24.                                         //    "B" point of a qix structure.
  25.  
  26. /**********************************************************************/
  27.  
  28.  
  29. @implementation QixView
  30.  
  31. /**********************************************************************/
  32.  
  33. - newWindow
  34. {
  35.     [ self resetQix : &head : NO ];
  36.     [ self resetQix : &tail : YES ];
  37.     
  38.     return self;
  39. }
  40.  
  41. /**********************************************************************/
  42.  
  43. - (const char *) windowTitle
  44. {
  45.     return ( const char * ) "Qix Lines";
  46. }
  47.  
  48. /**********************************************************************/
  49.  
  50. - initFrame : ( const NXRect * ) frameRect
  51. {
  52.     [ super initFrame : frameRect ];
  53.     
  54.     [ self setOpaque : YES ];
  55.     [ self setClipping : NO ];
  56.     
  57.     [ self resetQix : &head : NO ];
  58.     [ self resetQix : &tail : YES ];
  59.     
  60.     return self;
  61. }
  62.  
  63. /**********************************************************************/
  64.  
  65. - sizeTo : ( NXCoord ) width : ( NXCoord ) height
  66. {
  67.     [ super sizeTo : width : height ];
  68.     
  69.     [ self resetQix : &head : NO ];
  70.     [ self resetQix : &tail : YES ];
  71.     
  72.     return self;
  73. }
  74.  
  75. /**********************************************************************/
  76.  
  77. - resetQix : ( QIX * ) qix : ( BOOL ) resetControls
  78. {
  79.     if( resetControls == YES )
  80.         tailLen = INITLEN;
  81.     
  82.     qix->pointA.x = bounds.size.width / 3.0;
  83.     qix->pointA.y = bounds.size.height / 3.0;
  84.     qix->pointA.x_dir = RIGHT;
  85.     qix->pointA.y_dir = DOWN;
  86.     qix->pointA.x_inc = A_BASE_INC;
  87.     qix->pointA.y_inc = A_BASE_INC;
  88.     qix->pointA.orig_inc = A_BASE_INC;
  89.     
  90.     qix->pointB.x = bounds.size.width / 2.0;
  91.     qix->pointB.y = bounds.size.height / 2.0;
  92.     qix->pointB.x_dir = LEFT;
  93.     qix->pointB.y_dir = UP;
  94.     qix->pointB.x_inc = B_BASE_INC;
  95.     qix->pointB.y_inc = B_BASE_INC;
  96.     qix->pointB.orig_inc = B_BASE_INC;
  97.     
  98.     return self;
  99. }
  100.  
  101. /**********************************************************************/
  102.     
  103. - setQixPoint : ( MVPOINT * ) point
  104. {
  105.     if( point->x >= bounds.size.width )
  106.     {
  107.         point->x_dir = LEFT;
  108.         point->x_inc = point->orig_inc;
  109.     }
  110.     else if( point->x <= 0 )
  111.         point->x_dir = RIGHT;
  112.     
  113.     if( point->x_dir == RIGHT )
  114.     {
  115.         point->x += point->x_inc;
  116.         point->x_inc -= .009;
  117.     }
  118.     else
  119.     {
  120.         point->x -= point->x_inc;
  121.         point->x_inc += .03;
  122.     }
  123.  
  124.     if( point->y >= bounds.size.height )
  125.     {
  126.         point->y_dir = DOWN;
  127.         point->y_inc = point->orig_inc;
  128.     }
  129.     else if( point->y <= 0 )
  130.         point->y_dir = UP;
  131.         
  132.     if( point->y_dir == UP )
  133.     {
  134.         point->y += point->y_inc;
  135.         point->y_inc -= .009;
  136.     }
  137.     else
  138.     {
  139.         point->y -= point->y_inc;
  140.         point->y_inc += .06;
  141.     }
  142.         
  143.     return self;
  144. }
  145.  
  146. /**********************************************************************/
  147.  
  148. - drawQix : ( QIX ) qix
  149. {
  150.     PSsetlinewidth( 0.5 );
  151.  
  152.     PSmoveto( qix.pointA.x, qix.pointA.y );
  153.     PSlineto( qix.pointB.x, qix.pointB.y );
  154.     PSstroke( );
  155.     
  156.     return self;
  157. }
  158.  
  159. /**********************************************************************/
  160.  
  161. - oneStep
  162. {
  163.     if( tailLen )
  164.         --tailLen;
  165.     else
  166.     {
  167.         PSsetgray( NX_BLACK );
  168.         [ self drawQix : tail ];
  169.         [ self setQixPoint :  &tail.pointA ];
  170.         [ self setQixPoint :  &tail.pointB ];
  171.     }
  172.     
  173.     PSsetgray( NX_WHITE );
  174.     [ self drawQix : head ];
  175.     [ self setQixPoint : &head.pointA ];
  176.     [ self setQixPoint : &head.pointB ];
  177.     
  178.     return self;
  179. }
  180.  
  181. /**********************************************************************/
  182.  
  183. - drawSelf : ( NXRect * ) r : ( int ) count
  184. {     
  185.     if (!r || !count)
  186.         return self;
  187.         
  188.     PSsetgray( NX_BLACK );
  189.     
  190.     NXRectFill( r );
  191.     
  192.     return self;
  193.     
  194. }
  195.  
  196. /**********************************************************************/
  197.  
  198. @end
  199.